mui.previewImage();
var COUNT = 10;
var n = -1;
var appKey = 'pwe86ga5ema46';
var token = readData(localStorage.noticeToken);
var phone = readData(localStorage.phone);
var guideId = readData(localStorage.guideId);
//融云初始化
RongIMLib.RongIMClient.init(appKey);
// 私聊,其他会话选择相应的消息类型即可。
var conversationtype = RongIMLib.ConversationType.GROUP;
// 目标 Id
var targetId = readData(localStorage.groupId);
console.log('targetId'+readData(localStorage.groupId))
var member = [],
	myPic, myName;
if (readData(localStorage.mem)) {
	member = eval('(' + readData(localStorage.mem) + ')');
	for (var i = 0; i < member.length; i++) {
		if (member[i]['huanid'] == readData(localStorage.huanId)) {
			myPic = member[i]['headimg'];
			if (member[i]['nickname']) {
				myName = member[i]['nickname']
			} else {
				myName = member[i]['account'].substring(0, 3) + '****' + member[i]['account'].substring(7);
			}
		}
	}
}
//昵称头像
var youPic, youName;
function nichen(message) {
	for (var i = 0; i < member.length; i++) {
		if (member[i]['id'] == message) {
			youPic = member[i]['headimg'] || member[i]['headImg'];
			if (member[i]['nickname']) {
				youName = member[i]['nickname'];
			} else if (member[i]['account']) {
				youName = member[i]['account'].substring(0, 3) + '****' + member[i]['account'].substring(7);
			} else {
				youName = '群主';
			}
		}
	}
}
//创建websql
var db = openDatabase('messageChat', '1.0', 'messageChatOfHistory DB', 4 * 1024 * 1024);
db.transaction(function(tx) {
	tx.executeSql('CREATE TABLE IF NOT EXISTS MessageHistory ( Id, Phone,GuideId, Message)');
	tx.executeSql('CREATE TABLE IF NOT EXISTS CurentOtherMessage( Id, Phone,GuideId, MessageType, Message)');
});
var historyMsg = [];
var unreadMsg = [];
//读取历史消息
db.transaction(function(tx) {
	tx.executeSql('SELECT * FROM MessageHistory WHERE Id=? AND Phone=? AND GuideId=?', [targetId, phone, guideId], function(tx, results) {
		var len = results.rows.length,
			i;
		if (len > 0) {
			for (i = 0; i < len; i++) {
				//console.log(JSON.stringify(results.rows.item(i)));
				historyMsg.push(eval('(' + results.rows.item(i).Message + ')'));
			}
			n = historyMsg.length - 1;
			moreMsg(4);
		}
	}, null);
});

function moreMsg(hisnumber) {
	var table = document.getElementById('history');
	//console.log(JSON.stringify(historyMsg))
	while (n >= 0) {
		for (var i = n; i > n - hisnumber; i--) {
			if (i >= 0) {
				var div = document.createElement('div');
				var cname = '';
				var touxiang = '';
				var textContent;
				var imageContent = '<img class="msg-content-image" src="' + historyMsg[i].content + '" style="max-width: 100px;" data-preview-src="" data-preview-group="1" />';
				var soundContent = '<span class="mui-icon mui-icon-mic" style="font-size: 18px;font-weight: bold;"></span><span class="play-state">点击播放</span>';
				if (historyMsg[i].sender == "self") {
					cname = 'msg-item-self';
					div.className = 'msg-item msg-item-self';
					touxiang = '<i class="msg-user mui-icon mui-icon-person"></i>';
					if (historyMsg[i].type == 'text') {
						textContent = '<div class="msg-content"><div class="msg-content-inner">' + historyMsg[i].content + '</div><div class="msg-content-arrow"></div></div><div class="mui-item-clear"></div>';
					}
					if (historyMsg[i].type == 'sound') {
						textContent = '<div class="msg-content" msg-content="' + historyMsg[i].content + '" onclick="playSelf(this)" ><div class="msg-content-inner">' + soundContent + '</div><div class="msg-content-arrow"></div></div><div class="mui-item-clear"></div>';
					}
					if (historyMsg[i].type == 'image') {
						textContent = '<div class="msg-content"><div class="msg-content-inner">' + imageContent + '</div><div class="msg-content-arrow"></div></div><div class="mui-item-clear"></div>';
					}
				} else {
					div.className = 'msg-item ';
					touxiang = '<img class="msg-user-img" src="'+ historyMsg[i].content.headimg +'" alt="" onerror="javascript:this.src=\'../../image/my/pl_tp.png\'"/><div class="nickName" id="nickName">' +historyMsg[i].name + '</div>';
					if (historyMsg[i].type == 'text') {
						textContent = '<div class="msg-content"><div class="msg-content-inner">' + historyMsg[i].content + '</div><div class="msg-content-arrow"></div></div><div class="mui-item-clear"></div>';
					}
					if (historyMsg[i].type == 'sound') {
						textContent = '<div class="msg-content" msg-content="' + historyMsg[i].content + '" onclick="playOther(this)" ><div class="msg-content-inner">' + soundContent + '</div><div class="msg-content-arrow"></div></div><div class="mui-item-clear"></div>';
					}
					if (historyMsg[i].type == 'image') {
						textContent = '<div class="msg-content"><div class="msg-content-inner">' + imageContent + '</div><div class="msg-content-arrow"></div></div><div class="mui-item-clear"></div>';
					}
				}
				div.innerHTML = touxiang + textContent;
				table.insertBefore(div, table.firstChild);
			} else {
				if(hisnumber!=4){
					mui.toast("没有更多消息啦....");
				}				
				break;
			}
		}
		n -= hisnumber;
		break;
	}
	if (n < 0 && hisnumber!=4) {
		mui.toast("没有更多消息啦....");
	}

}
function playSelf(obj) {
	var playState = obj.getElementsByClassName('play-state')[0];
	var msgContent = obj.getAttribute('msg-content');
	player = plus.audio.createPlayer(msgContent);
	playState.innerText = '正在播放...';
	player.play(function() {
		playState.innerText = '点击播放';
	}, function(e) {
		playState.innerText = '点击播放';
	});
}

function playOther(obj) {
	var playState = obj.getElementsByClassName('play-state')[0];
	var msgContent = obj.getAttribute('msg-content');
	var isInit = RongIMLib.RongIMVoice.init();
	RongIMLib.RongIMVoice.preLoaded(msgContent);
	var duration = msgContent.length / 1024;
	playState.innerText = '正在播放...';
	RongIMLib.RongIMVoice.play(msgContent, duration);
	setTimeout(function() {
		playState.innerText = '点击播放';
	}, duration * 1000);
}
(function($, doc) {
	var WEB_XHR_POLLING = true;
	var MIN_SOUND_TIME = 800;
	console.log(token + 'targetId' + targetId);
	$.init({
		gestureConfig: {
			tap: true, //默认为true
			doubletap: true, //默认为false
			longtap: true, //默认为false
			swipe: true, //默认为true
			drag: true, //默认为true
			hold: true, //默认为false，不监听
			release: true //默认为false，不监听
		}
	});
	template.config('escape', false);
	var type = '1';
	//清除未读消息
	//clearUnreadMsg(conversationtype, targetId);
	$.plusReady(function() {
		//读取未读消息
		db.transaction(function(tx) {
			tx.executeSql('SELECT * FROM CurentOtherMessage WHERE Id=? AND Phone=? AND MessageType=? AND GuideId=?', [targetId, phone, 3, guideId], function(tx, results) {
				var len = results.rows.length,
					i;
				if (len > 0) {
					for (i = 0; i < len; i++) {
						//console.log(results.rows.item(i).Message);
						messageSort(eval('(' + results.rows.item(i).Message + ')'));
					}
					tx.executeSql('DELETE FROM CurentOtherMessage  WHERE Id=? AND Phone=? AND MessageType=? AND GuideId=?', [targetId, phone, 3, guideId]);
				    plus.webview.getWebviewById('home.html').reload(true);
				}
			}, null);
		})
		//消息类型判断
		function messageSort(message) {
			nichen(message.senderUserId);
			switch (message.messageType) {
				case 'TextMessage':
					// message.content.content => 消息内容receivedTime
					var rmsg = {
						sender: 'zs',
						type: 'text',
						content: message.content.content,
						time: message.receivedTime,
						name: youName,
						headimg: youPic,
						userId: message.senderUserId
					};
					record.push(rmsg);
					bindMsgList();
					dbInsert(rmsg);
					console.log(JSON.stringify(message));
					break;
				case 'VoiceMessage':
					// 对声音进行预加载              data:audio/amr;base64,  
					// message.content.content 格式为 AMR 格式的 base64 码
					console.log(message.content.content);
					var rmsg = {
						sender: 'zs',
						type: 'sound',
						content: message.content.content,
						time: message.receivedTime,
						name: youName,
						headimg: youPic,
						userId: message.senderUserId
					};
					record.push(rmsg);
					bindMsgList();
					dbInsert(rmsg);
					break;
				case 'ImageMessage':
					// message.content.content => 图片缩略图 base64。data:image/jpeg;base64,
					// message.content.imageUri => 原图 URL。
					var rmsg = {
						sender: 'zs',
						type: 'image',
						content: 'data:image/jpeg;base64,' + message.content.content,
						time: message.receivedTime,
						name: youName,
						headimg: youPic,
						userId: message.senderUserId
					};
					record.push(rmsg);
					bindMsgList();
					dbInsert(rmsg);
					console.log(JSON.stringify(rmsg));
					break;
				default:
					// do something...
			}
		}
		// 设置连接监听状态 （ status 标识当前连接状态 ）连接状态监听器
		RongIMClient.setConnectionStatusListener({
			onChanged: function(status) {
				switch (status) {
					case RongIMLib.ConnectionStatus.CONNECTED:
						console.log('链接成功');
						break;
					case RongIMLib.ConnectionStatus.CONNECTING:
						console.log('正在链接');
						break;
					case RongIMLib.ConnectionStatus.DISCONNECTED:
						console.log('断开连接');
						break;
				}
				console.log(status);
			}
		});

		// 消息监听器
		RongIMClient.setOnReceiveMessageListener({
			// 接收到的消息
			onReceived: function(message) {
				// 判断消息类型
				if(!message.content.extra){
					message.content.extra=message.senderUserId;
				}
				if (message.conversationType == 3 && message.content.extra == guideId) {
					messageSort(message);
				} else {
					dbInsertOther(message);
				}
			}
		});

		//连接融云服务器
		RongIMClient.connect(token, {
			onSuccess: function(userId) {
				console.log("Login successfully." + userId);
			},
			onTokenIncorrect: function() {
				console.log('token无效');
			},
			onError: function(errorCode) {
				var info = '';
				switch (errorCode) {
					case RongIMLib.ErrorCode.TIMEOUT:
						info = '超时';
						break;
					case RongIMLib.ErrorCode.IDENTIFIER_REJECTED:
						info = 'appkey不正确';
						break;
					case RongIMLib.ErrorCode.SERVER_UNAVAILABLE:
						info = '服务器不可用';
						break;
				}
				console.log(errorCode);
			}
		});

		plus.webview.currentWebview().setStyle({
			softinputMode: "adjustResize"
		});
		var showKeyboard = function() {
			if ($.os.ios) {
				var webView = plus.webview.currentWebview().nativeInstanceObject();
				webView.plusCallMethod({
					"setKeyboardDisplayRequiresUserAction": false
				});
			} else {
				var Context = plus.android.importClass("android.content.Context");
				var InputMethodManager = plus.android.importClass("android.view.inputmethod.InputMethodManager");
				var main = plus.android.runtimeMainActivity();
				var imm = main.getSystemService(Context.INPUT_METHOD_SERVICE);
				imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
				//var view = ((ViewGroup)main.findViewById(android.R.id.content)).getChildAt(0);
				imm.showSoftInput(main.getWindow().getDecorView(), InputMethodManager.SHOW_IMPLICIT);
			}
		};
		var record = [];
		var ui = {
			body: doc.querySelector('body'),
			footer: doc.querySelector('footer'),
			footerRight: doc.querySelector('.footer-right'),
			footerLeft: doc.querySelector('.footer-left'),
			btnMsgType: doc.querySelector('#msg-type'),
			boxMsgText: doc.querySelector('#msg-text'),
			boxMsgSound: doc.querySelector('#msg-sound'),
			btnMsgImage: doc.querySelector('#msg-image'),
			areaMsgList: doc.querySelector('#msg-list'),
			nowMsgList: doc.querySelector('#msg-now'),
			boxSoundAlert: doc.querySelector('#sound-alert'),
			h: doc.querySelector('#h'),
			content: doc.querySelector('.mui-content')
		};
		ui.h.style.width = ui.boxMsgText.offsetWidth + 'px';
		//alert(ui.boxMsgText.offsetWidth );
		var footerPadding = ui.footer.offsetHeight - ui.boxMsgText.offsetHeight;
		var msgItemTap = function(msgItem, event) {
			var msgType = msgItem.getAttribute('msg-type');
			var msgContent = msgItem.getAttribute('msg-content');
			var msgSender = msgItem.getAttribute('msg-sender');
			var playState = msgItem.querySelector('.play-state');
			if (msgSender == 'self') {
				if (msgType == 'sound') {
					player = plus.audio.createPlayer(msgContent);					
					playState.innerText = '正在播放...';
					player.play(function() {
						playState.innerText = '点击播放';
					}, function(e) {
						playState.innerText = '点击播放';
					});
				}
			} else {
				if (msgType == 'sound') {
					var isInit = RongIMLib.RongIMVoice.init();
					RongIMLib.RongIMVoice.preLoaded(msgContent);
					var duration = msgContent.length / 1024;
					//setTimeout(function() {
						playState.innerText = '正在播放...';
						RongIMLib.RongIMVoice.play(msgContent, duration);
					//}, 100);
					setTimeout(function() {
						playState.innerText = '点击播放';
					}, duration*1000);
				}
			}
		};
		var imageViewer = new $.ImageViewer('.msg-content-image', {
			dbl: false
		});
		var bindMsgList = function() {
			//绑定数据:			
			ui.nowMsgList.innerHTML = template('msg-template', {
				"record": record
			});
			var msgItems = ui.areaMsgList.querySelectorAll('.msg-item');
			[].forEach.call(msgItems, function(item, index) {
				item.addEventListener('tap', function(event) {
					msgItemTap(item, event);
				}, false);
			});
			imageViewer.findAllImage();
			ui.areaMsgList.scrollTop = ui.areaMsgList.scrollHeight + ui.areaMsgList.offsetHeight;
		};

		bindMsgList();

		window.addEventListener('resize', function() {
			ui.areaMsgList.scrollTop = ui.areaMsgList.scrollHeight + ui.areaMsgList.offsetHeight;
		}, false);

		var send = function(msg) {
			toRobot(msg);
		};
		var toRobot = function(message) {
			if (message.type == 'text') {
				var msg = new RongIMLib.TextMessage({
					content: message.content,
					extra: guideId
				});
				rongYunSend(msg, message);
			} else if (message.type == 'image') {
				compress(message);
			} else {
				basbase64(message, message);
			}
		};
		//保存接收到的消息
		function dbInsert(msg) {
			db.transaction(function(tx) {
				tx.executeSql('INSERT INTO MessageHistory (Id, Phone,GuideId, Message) VALUES (?,?,?,?)', [targetId, phone, guideId, JSON.stringify(msg)]);
			});
		}
		//保存收到其他人的消息
		function dbInsertOther(msg) {
			if(msg.conversationType==1){
				db.transaction(function(tx) {
					tx.executeSql('INSERT INTO CurentOtherMessage (Id, Phone, GuideId, MessageType, Message) VALUES (?,?,?,?,?)', [msg.senderUserId, phone, msg.content.extra, msg.conversationType, JSON.stringify(msg)]);
				});
			}else{
				db.transaction(function(tx) {
					tx.executeSql('INSERT INTO CurentOtherMessage (Id, Phone, GuideId, MessageType, Message) VALUES (?,?,?,?,?)', [msg.targetId, phone, msg.content.extra, msg.conversationType, JSON.stringify(msg)]);
				});
			}
			plus.webview.getWebviewById('circleChatList.html').reload(true);
		}

		function compress(message) {
			var base64Str;
			var imgUrl = message.content.split('/');
			plus.zip.compressImage({
				src: message.content,
				dst: "_doc/" + imgUrl[imgUrl.length - 1],
				overwrite: true,
				width: '120px',
				//height:'40%',
				quality: 50
			}, function(event) {
				basbase64({
					sender: 'self',
					type: 'image',
					content: event.target
				}, message);
			}, function(err) {
				console.log(JSON.stringify(err))
			});
		}

		function basbase64(bmain, msgsend) {
			plus.io.resolveLocalFileSystemURL(bmain.content, function(entry) {
				// 可通过entry对象操作test.html文件 
				entry.file(function(file) {
					var fileReader = new plus.io.FileReader();
					fileReader.onloadend = function(e) {
						var str=e.target.result;
						base64Str = str.slice(str.indexOf(',')+1);								
						if (bmain.type == 'image') {//图片发送
							var msg = new RongIMLib.ImageMessage({
								content: base64Str,
								imageUri: bmain.content,
								extra: guideId
							});							
						}
						//音频发送
						if (bmain.type == 'sound') {
							var msg = new RongIMLib.VoiceMessage({
								content: base64Str,
								duration: msgsend.duration,
								extra: guideId
							});
						}
						rongYunSend(msg, msgsend);
					}
					fileReader.readAsDataURL(file);
				});
			}, function(e) {
				console.log("Resolve file URL failed: " + e.message);
			});
		}

		//发送到融云
		function rongYunSend(msg, msgsend) {
			RongIMClient.getInstance().sendMessage(conversationtype, targetId, msg, {
				onSuccess: function(message) {
					//message 为发送的消息对象并且包含服务器返回的消息唯一Id和发送消息时间戳
					console.log('Send successfully' + JSON.stringify(message))
					record.push(msgsend);
					bindMsgList();
					dbInsert(msgsend);
				},
				onError: function(errorCode, message) {
					var info = '';
					switch (errorCode) {
						case RongIMLib.ErrorCode.TIMEOUT:
							info = '超时';
							break;
						case RongIMLib.ErrorCode.NOT_IN_GROUP:
							info = '不在群组中';
							break;
						default:
							info = x;
							break;
					}
					console.log(errorCode+'发送失败:' + info);
				}
			});
		}

		function msgTextFocus() {
			ui.boxMsgText.focus();
			setTimeout(function() {
				ui.boxMsgText.focus();
			}, 150);
		}
		//解决长按“发送”按钮，导致键盘关闭的问题；
		ui.footerRight.addEventListener('touchstart', function(event) {
			if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
				msgTextFocus();
				event.preventDefault();
			}
		});
		//解决长按“发送”按钮，导致键盘关闭的问题；
		ui.footerRight.addEventListener('touchmove', function(event) {
			if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
				msgTextFocus();
				event.preventDefault();
			}
		});
		
		ui.footerRight.addEventListener('release', function(event) {
			if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
				//showKeyboard();
				ui.boxMsgText.focus();
				setTimeout(function() {
					ui.boxMsgText.focus();
				}, 150);
				//event.detail.gesture.preventDefault();
				var DateTime = new Date().getTime();
				send({
					sender: 'self',
					type: 'text',
					content: ui.boxMsgText.value.replace(new RegExp('\n', 'gm'), '<br/>'),
					time: DateTime
				});
				ui.boxMsgText.value = '';
				$.trigger(ui.boxMsgText, 'input', null);
			} else if (ui.btnMsgType.classList.contains('mui-icon-mic')) {
				ui.btnMsgType.classList.add('mui-icon-compose');
				ui.btnMsgType.classList.remove('mui-icon-mic');
				ui.boxMsgText.style.display = 'none';
				ui.boxMsgSound.style.display = 'block';
				ui.boxMsgText.blur();
				document.body.focus();
			} else if (ui.btnMsgType.classList.contains('mui-icon-compose')) {
				ui.btnMsgType.classList.add('mui-icon-mic');
				ui.btnMsgType.classList.remove('mui-icon-compose');
				ui.boxMsgSound.style.display = 'none';
				ui.boxMsgText.style.display = 'block';
				//--
				//showKeyboard();
				ui.boxMsgText.focus();
				setTimeout(function() {
					ui.boxMsgText.focus();
				}, 150);
			}
		}, false);
		ui.footerLeft.addEventListener('tap', function(event) {
			var btnArray = [{
				title: "拍照"
			}, {
				title: "从相册选择"
			}];
			plus.nativeUI.actionSheet({
				title: "选择照片",
				cancel: "取消",
				buttons: btnArray
			}, function(e) {
				var index = e.index;
				var DateTime = new Date().getTime();
				switch (index) {
					case 0:
						break;
					case 1:
						var cmr = plus.camera.getCamera();
						cmr.captureImage(function(path) {
							send({
								sender: 'self',
								type: 'image',
								content: "file://" + plus.io.convertLocalFileSystemURL(path),
								time: DateTime
							});
						}, function(err) {});
						break;
					case 2:
						plus.gallery.pick(function(path) {
							send({
								sender: 'self',
								type: 'image',
								content: path,
								time: DateTime
							});
						}, function(err) {}, null);
						break;
				}
			});
		}, false);
		var setSoundAlertVisable = function(show) {
			if (show) {
				ui.boxSoundAlert.style.display = 'block';
				ui.boxSoundAlert.style.opacity = 1;
			} else {
				ui.boxSoundAlert.style.opacity = 0;
				//fadeOut 完成再真正隐藏
				setTimeout(function() {
					ui.boxSoundAlert.style.display = 'none';
				}, 200);
			}
		};
		var recordCancel = false;
		var recorder = null;
		var audio_tips = document.getElementById("audio_tips");
		var startTimestamp = null;
		var stopTimestamp = null;
		var stopTimer = null;
		ui.boxMsgSound.addEventListener('hold', function(event) {
			recordCancel = false;
			if (stopTimer) clearTimeout(stopTimer);
			audio_tips.innerHTML = "手指上划，取消发送";
			ui.boxSoundAlert.classList.remove('rprogress-sigh');
			setSoundAlertVisable(true);
			recorder = plus.audio.getRecorder();
			if (recorder == null) {
				plus.nativeUI.toast("不能获取录音对象");
				return;
			}
			startTimestamp = (new Date()).getTime();
			recorder.record({
				filename: "_doc/audio/"
			}, function(path) {
				if (recordCancel) return;
				var DateTime = new Date().getTime();
				var vtime = (stopTimestamp - startTimestamp) / 1000;
				var duration = Math.round(vtime);
				send({
					sender: 'self',
					type: 'sound',
					content: path,
					time: DateTime,
					duration: duration
				});
			}, function(e) {
				plus.nativeUI.toast("录音时出现异常: " + e.message);
			});
		}, false);
		ui.body.addEventListener('drag', function(event) {
			//console.log('drag');
			if (Math.abs(event.detail.deltaY) > 50) {
				if (!recordCancel) {
					recordCancel = true;
					if (!audio_tips.classList.contains("cancel")) {
						audio_tips.classList.add("cancel");
					}
					audio_tips.innerHTML = "松开手指，取消发送";
				}
			} else {
				if (recordCancel) {
					recordCancel = false;
					if (audio_tips.classList.contains("cancel")) {
						audio_tips.classList.remove("cancel");
					}
					audio_tips.innerHTML = "手指上划，取消发送";
				}
			}
		}, false);
		ui.boxMsgSound.addEventListener('release', function(event) {
			if (audio_tips.classList.contains("cancel")) {
				audio_tips.classList.remove("cancel");
				audio_tips.innerHTML = "手指上划，取消发送";
			}
			
			stopTimestamp = (new Date()).getTime();
			if (stopTimestamp - startTimestamp < MIN_SOUND_TIME) {
				audio_tips.innerHTML = "录音时间太短";
				ui.boxSoundAlert.classList.add('rprogress-sigh');
				recordCancel = true;
				stopTimer = setTimeout(function() {
					setSoundAlertVisable(false);
				}, 800);
			} else {
				setSoundAlertVisable(false);
			}
			recorder.stop();
		}, false);
		ui.boxMsgSound.addEventListener("touchstart", function(e) {
			//console.log("start....");
			e.preventDefault();
		});
		ui.boxMsgText.addEventListener('input', function(event) {
			ui.btnMsgType.classList[ui.boxMsgText.value == '' ? 'remove' : 'add']('mui-icon-paperplane');
			ui.btnMsgType.setAttribute("for", ui.boxMsgText.value == '' ? '' : 'msg-text');
			ui.h.innerText = ui.boxMsgText.value.replace(new RegExp('\n', 'gm'), '\n-') || '-';
			ui.footer.style.height = (ui.h.offsetHeight + footerPadding) + 'px';
			ui.content.style.paddingBottom = ui.footer.style.height;
		});
		var focus = false;
		ui.boxMsgText.addEventListener('tap', function(event) {
			ui.boxMsgText.focus();
			setTimeout(function() {
				ui.boxMsgText.focus();
			}, 0);
			focus = true;
			setTimeout(function() {
				focus = false;
			}, 1000);
			event.detail.gesture.preventDefault();
		}, false);
		//点击消息列表，关闭键盘
		ui.areaMsgList.addEventListener('click', function(event) {
			if (!focus) {
				ui.boxMsgText.blur();
			}
		})

	});
}(mui, document));